package models

import (
	"fmt"
	"wikisaver/config"

	_ "github.com/go-sql-driver/mysql"
	"github.com/jmoiron/sqlx"
)

var Conn *sqlx.DB
var SaveChan chan AddAble

func init() {
	var err error
	c := config.Conf.DB
	dbUrl := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", c.Username, c.Password, c.Host, c.Port, c.DataBase)
	Conn, err = sqlx.Connect("mysql", dbUrl)
	if err != nil {
		fmt.Println("failed to connect database")
		panic(err)
	}

	SaveChan = make(chan AddAble)
}
